﻿using MySchool;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyKTV
{
    public partial class Form8 : Form
    {
        string targetPath;
        DBHelper dB = new DBHelper();
        DataSet ds = new DataSet();
        string name;

        string da;
        int count;
        string lu;
        string name1;

        public string singer_name { get; internal set; }

        public string singertype_name { get; internal set; }

        public string singer_gender { get; internal set; }

        public string singer_photo_url { get; internal set; }

        public string singer_description { get; internal set; }

        public string Lu { get => lu; set => lu = value; }

        public Form8()
        {
            InitializeComponent();
        }

        private void Form8_Load(object sender, EventArgs e)
        {
            dB.OpenConnection();
            name = singer_photo_url;
       //     name1 = singer_photo_url;
            string sql = "select resource_path from resource_path where resource_id = 1 ";

            string name3 = null;

            SqlCommand command = new SqlCommand(sql, dB.Connection);

            SqlDataReader reader = command.ExecuteReader();





            while (reader.Read())

            {

                name3 = reader["resource_path"].ToString();

            }
            reader.Close();
            dB.OpenConnection();
            string sql1 = "select resource_path from resource_path where resource_id=1";

            SqlCommand comm = new SqlCommand(sql1, dB.Connection);

            SqlDataReader data = comm.ExecuteReader();



            while (data.Read())

            {



                targetPath = data["resource_path"].ToString();



            }

            data.Close();


            //this.pictureBox1.Image = Image.FromFile(name + "\\" + singer_photo_url);





            // this.pictureBox2.Image= Lu;

            dB.OpenConnection();
            textBox1.Text= singer_name;
           

            if (singer_gender == "男")

            {

                this.radioButton1.Checked = true;

            }

            else if (singer_gender == "女")

            {

                this.radioButton3.Checked = true;

            }

            else

            {

                this.radioButton3.Checked = true;

            }

            this.comboBox1.Text = singertype_name;
            this.pictureBox1.Name = singer_photo_url;
            this.pictureBox1.Image= Image.FromFile(name3 + "\\" + singer_photo_url);
            this.textBoxEx1.Text = singer_description;
                




        }

        private void button1_Click(object sender, EventArgs e)
        {
            string jian = singer_name;

            string sa;

            if (radioButton2.Checked == true)

            {

                //this.radioButton2.Text = "女";

                sa = "女";

            }

            else if (radioButton3.Checked)

            {

                // this.radioButton2.Text = "组合";

                sa = "组合";

            }

            else

            {

                //this.radioButton2.Text = "男";

                sa = "男";

            }



            if (this.comboBox1.Text == "大陆")

            {

                count = 1;

            }

            else if (this.comboBox1.Text == "香港")

            {

                count = 2;

            }

            else if (this.comboBox1.Text == "台湾")

            {

                count = 3;

            }

            else if (this.comboBox1.Text == "欧美")

            {

                count = 4;

            }

            else if (this.comboBox1.Text == "日韩")

            {

                count = 5;

            }

            string str = "update singer_info set singer_name=N'" + this.textBox1.Text + "',singertype_id=N'" + count + "',singer_gender=N'" + sa + "',singer_photo_url=N'" + name + "',singer_description=N'" + this.textBoxEx1.Text

                + "' where singer_info.singer_name=N'" + jian + "'";

            dB.OpenConnection();

            SqlCommand com = new SqlCommand(str, dB.Connection);

            int reader = com.ExecuteNonQuery();



            if (reader > 0)

            {

                MessageBox.Show("修改成功");

                return;

            }

            else

            {

                MessageBox.Show("!!!!!!", "错误", MessageBoxButtons.AbortRetryIgnore);

            }



        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {//弹出选择文件框

            OpenFileDialog openFileDialog = new OpenFileDialog();

            //打开文件框

            DialogResult result = openFileDialog.ShowDialog();



            if (result == DialogResult.OK)

            {

                // Image.FromFile从路径中拿到图片

                string name2 = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf(".") + 1);

                if (name2 != "jpg")

                {

                    MessageBox.Show("文件类型错误！");

                    return;

                }

                this.pictureBox1.Image = Image.FromFile(openFileDialog.FileName);

                name = openFileDialog.FileName.Substring(openFileDialog.FileName.LastIndexOf("\\") + 1);







                //Copy复制只能实现一个文件到另一个文件中，两个参数第一个文件，第二个目标路径

                 File.Copy(openFileDialog.FileName, targetPath + "\\" + name);



            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}

      